package com.hks360.car_treasure.trail.model;

import android.content.Context;
import android.widget.Toast;

import com.hks360.car_treasure.manager.CommonDataManager;
import com.hks360.car_treasure.model.JourneyLocation;
import com.hks360.car_treasure.util.DateUtils;
import com.hks360.car_treasure.util.LogUtil;
import com.hks360.library.nohttp.HttpCallback;
import com.hks360.library.util.DateUtil;
import com.hks360.nohttp.Response;

import java.util.Date;
import java.util.List;

import static com.hks360.car_treasure.util.GsonParseUtil.parseJourneyLocation;

public class TrailModelImpl implements TrailModel {
    private Context context;
    public TrailModelImpl(Context context) {
        this.context = context;
    }

    @Override
    public void readJourneyLocation(int what, String tboxid, String startTime, String endTime, final JourneyListener listener) {
        HttpCallback<String> httpCallback = new HttpCallback<String>() {
            @Override
            public void onSuccess(int what, Response<String> response) {
                if(response != null) {
                    List<JourneyLocation> journeyLocations = parseJourneyLocation(response.get());
                    listener.onSuccess(what, journeyLocations);
                }else {
                    Toast.makeText(context,"返回数据为空",Toast.LENGTH_LONG).show();
                }

            }
            @Override
            public void onFailed(int what) {
                listener.onFailed(what);
            }

            @Override
            public void onStart(int what) {
                listener.onStart(what);
            }

            @Override
            public void onFinish(int what) {
                listener.onFinish(what);
            }
        };
        CommonDataManager.getInstance(context).readJourneyLoaction(what,tboxid, startTime, endTime, httpCallback);
    }
    public interface JourneyListener {
        void onSuccess(int what, List<JourneyLocation> journeyLocations);

        void onFailed(int what);

        void onStart(int what);

        void onFinish(int what);
    }
}
